package com.jz.community.modulemine.rechargephone.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jz.community.basecomm.utils.RxDataTool;
import com.jz.community.modulemine.R;
import com.jz.community.modulemine.rechargephone.bean.PhonePriceBean;

import java.util.List;

public class PhoneMoneyAdapter extends BaseQuickAdapter<PhonePriceBean.EmbeddedBean.ContentBean, BaseViewHolder> {
    private String sPhone;

    public PhoneMoneyAdapter(int layoutResId, @Nullable List<PhonePriceBean.EmbeddedBean.ContentBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, PhonePriceBean.EmbeddedBean.ContentBean entity) {

        boolean isSelect = entity.isSelect();
        RelativeLayout parent = helper.getView(R.id.item_phone_parent);

        LinearLayout moneyLl = helper.getView(R.id.item_phone_money_ll);
        TextView money = helper.getView(R.id.item_phone_money);
        TextView moneyR = helper.getView(R.id.item_phone_money_r);

        LinearLayout moneyNoLl = helper.getView(R.id.item_phone_money_no_ll);
        TextView moneyNo = helper.getView(R.id.item_phone_money_no);

        LinearLayout priceLl = helper.getView(R.id.item_phone_price_ll);
        TextView price = helper.getView(R.id.item_phone_price);
        TextView priceR = helper.getView(R.id.item_phone_price_r);

        money.setText(entity.getOriginalPrice());
        moneyNo.setText(entity.getOriginalPrice());
        price.setText(entity.getSellingPrice());

        if (!RxDataTool.isNullString(sPhone)) {
            if (sPhone.length() == 11) {
                moneyNoLl.setVisibility(View.GONE);
                moneyLl.setVisibility(View.VISIBLE);
                priceLl.setVisibility(View.VISIBLE);
            } else {
                moneyNoLl.setVisibility(View.VISIBLE);
                moneyLl.setVisibility(View.INVISIBLE);
                priceLl.setVisibility(View.INVISIBLE);
            }
        } else {
            moneyNoLl.setVisibility(View.VISIBLE);
            moneyLl.setVisibility(View.INVISIBLE);
            priceLl.setVisibility(View.INVISIBLE);
        }

        if (isSelect) {
            parent.setBackgroundResource(R.drawable.border_phone_red_line);
            moneyR.setTextColor(mContext.getResources().getColor(R.color.home_red));
            money.setTextColor(mContext.getResources().getColor(R.color.home_red));

            priceR.setTextColor(mContext.getResources().getColor(R.color.home_red));
            price.setTextColor(mContext.getResources().getColor(R.color.home_red));
        } else {
            parent.setBackgroundResource(R.drawable.border_phone_gray_line);
            moneyR.setTextColor(mContext.getResources().getColor(R.color.font_gary_999));
            money.setTextColor(mContext.getResources().getColor(R.color.font_gary_999));

            priceR.setTextColor(mContext.getResources().getColor(R.color.font_gary_999));
            price.setTextColor(mContext.getResources().getColor(R.color.font_gary_999));
        }

    }

    public void change(int oldPosition, int position) {
        mData.get(oldPosition).setSelect(false);
        mData.get(position).setSelect(true);
        notifyDataSetChanged();
    }

    public void changeStatus(String sPhone) {
        this.sPhone = sPhone;
    }
}
